package com.billManage.system.service.impl;

import java.util.Date;
import java.util.List;
import com.billManage.common.utils.DateUtils;
import com.billManage.system.domain.SysBillRecord;
import com.billManage.system.mapper.SysBillRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.billManage.system.mapper.SysBillMapper;
import com.billManage.system.domain.SysBill;
import com.billManage.system.service.ISysBillService;
import com.billManage.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 票据管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-05-14
 */
@Service
public class SysBillServiceImpl implements ISysBillService 
{
    @Autowired
    private SysBillMapper sysBillMapper;
    @Autowired
    private SysBillRecordMapper sysBillRecordMapper;

    /**
     * 查询票据管理
     * 
     * @param billId 票据管理主键
     * @return 票据管理
     */
    @Override
    public SysBill selectSysBillByBillId(Long billId)
    {
        return sysBillMapper.selectSysBillByBillId(billId);
    }

    /**
     * 查询票据管理列表
     * 
     * @param sysBill 票据管理
     * @return 票据管理
     */
    @Override
    public List<SysBill> selectSysBillList(SysBill sysBill)
    {
        return sysBillMapper.selectSysBillList(sysBill);
    }

    /**
     * 新增票据管理
     * 
     * @param sysBill 票据管理
     * @return 结果
     */
    @Override
    public int insertSysBill(SysBill sysBill)
    {
        sysBill.setCreateTime(DateUtils.getNowDate());
        return sysBillMapper.insertSysBill(sysBill);
    }

    /**
     * 修改票据管理
     * 
     * @param sysBill 票据管理
     * @return 结果
     */
    @Override
    @Transactional
    public int updateSysBill(SysBill sysBill)
    {
        //审核记录
        SysBillRecord sysBillRecord = new SysBillRecord();
        sysBillRecord.setBillId(sysBill.getBillId());
        sysBillRecord.setReason(sysBill.getReason());
        sysBillRecord.setReviewBy(sysBill.getReviewBy());
        sysBillRecord.setReviewTime(sysBill.getReviewTime());
        sysBillRecord.setCreateBy(sysBill.getReviewBy());
        sysBillRecord.setCreateTime(new Date());
        this.sysBillRecordMapper.insertSysBillRecord(sysBillRecord);

        sysBill.setUpdateTime(DateUtils.getNowDate());
        return sysBillMapper.updateSysBill(sysBill);
    }

    /**
     * 批量删除票据管理
     * 
     * @param billIds 需要删除的票据管理主键
     * @return 结果
     */
    @Override
    public int deleteSysBillByBillIds(String billIds)
    {
        return sysBillMapper.deleteSysBillByBillIds(Convert.toStrArray(billIds));
    }

    /**
     * 删除票据管理信息
     * 
     * @param billId 票据管理主键
     * @return 结果
     */
    @Override
    public int deleteSysBillByBillId(Long billId)
    {
        return sysBillMapper.deleteSysBillByBillId(billId);
    }

    @Override
    public SysBill selectSysBillOne(SysBill sysBill) {
        return sysBillMapper.selectSysBillOne(sysBill);
    }
}
